var http = require('../../utils/http.js')
var util = require('../../utils/util.js')
var localstorage = require('../../utils/localstorage.js')
var appInstance = getApp()
var page = 1;
var pageSize = 10;
Page({
  data: {
    datalist: [],
    isMore: true,
    isloading:false,
    searchWork:"",
  },
  onLoad: function (options) {
    var words=decodeURIComponent( options.words )
    this.setData({
      searchWork:words
    })
    this.getdatalist(words)
     wx.setNavigationBarTitle({
       title: words+"-改色膜选色助手",
     })
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (e) {

  },

 
  onReachBottom() {
    if (this.data.isMore) {
      page = page + 1;
      this.getdatalist(this.data.searchWork)
    }
  },

  onPullDownRefresh()
  {
    this.setData({
      datalist: [],
    })
    page = 1;
    this.getdatalist(this.data.searchWork)

  },

  getdatalist: function (   searchWork) {
    var _this = this;
    this.setData({
      isloading: true
    })

    var postdata = {
      "Page": page,
      "PageSize": pageSize,
      "searchWork": searchWork
    }
    http.request({
      url: 'car_caseServiceApi/page',
      method: "Post",
      data: postdata,
      callBack: (res) => {

        wx.stopPullDownRefresh()

        if (res.result.total == 0) {
          _this.setData({
            isloading: false
          })
      
          return;
        }
        let newArr = res.result.items;
        let totalPages = res.result.totalPages

       
        
        _this.setData({
          isloading: false,
          datalist: [..._this.data.datalist, ...newArr],
          isMore: page < totalPages
        })


      }
    })
  },


  onclickItem:function(e)
  {
   // console.log(e.currentTarget.dataset.id)
    var id=e.currentTarget.dataset.id;
    var title=e.currentTarget.dataset.title;
    wx.navigateTo({
      url: '/pages/case/details?id='+id+'&title='+title,
    })
  },

})